/**
 * Created by IntelliJ IDEA.
 * User: Taras_Brzezinsky
 * Date: 8/3/11
 * Time: 12:33 AM
 * To change this template use File | Settings | File Templates.
 */

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.FileReader;
import java.math.BigInteger;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.Arrays;

public class BinPal extends Thread {

    public BinPal() {
        this.input = new BufferedReader(new InputStreamReader(System.in));
        this.output = new PrintWriter(System.out);
        this.setPriority(Thread.MAX_PRIORITY);
    }

    public void run() {
        try {
            int m = nextInt();
            if (m == 1) {
                output.println(1);
                output.flush();
                output.close();
                System.exit(0);
            }
            long[] dp = new long[5000];
            dp[1] = 1;
            long[] p = new long[62];
            p[0] = 1;
            for (int i = 1; i <= 61; ++i)
                p[i] = p[i - 1] << 1;
            dp[2] = 1;

            int size;
            for (size = 3; dp[size - 1] <= 50000; ++size) {
                int current = (size - 2) >> 1;
                dp[size] = p[current] * p[(size - 2) & 1];
            }

            long[] partialSums = new long[size << 1];
            partialSums[0] = dp[0];
            for (int i = 1; i < size; ++i) {
                partialSums[i] = partialSums[i - 1] + dp[i];
            }
            --m;
            int current = 0;
            while (m >= partialSums[current]) {
                ++current;
            }

            m = m - (int) partialSums[current - 1];
            String temp = Integer.toBinaryString(m);
            int n = (current + 1) >> 1;
            --n;
            while (temp.length() < n)
                temp = "0" + temp;
            StringBuilder result = new StringBuilder();
            result.append(1);
            if (n != 0) {
                result.append(temp);
                for (int i = current % 2 == 1 ? temp.length() - 2 : temp.length() - 1; i >= 0; --i)
                    result.append(temp.charAt(i));
            }
            result.append(1);
            output.println(Integer.parseInt(result.toString(), 2));
            output.flush();
            output.close();

        } catch (Throwable e) {
            System.err.println(e.getMessage());
            System.err.println(Arrays.deepToString(e.getStackTrace()));
        }
    }


    public static void main(String[] args) {
        new BinPal().start();
    }

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }


    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens = null;
}
